package  
{
	import bulletbehavior.HomeTargetBehavior;
	import bulletbehavior.SplitBehavior
	import bulletbehavior.DieBehavior
	import bulletbehavior.TypeCyclingBehavior;
	import bulletbehavior.WaveBehaviorAngular;
	import org.flixel.FlxG;
	import turretbehavior.SpinningTurretBehavior;
	import turretbehavior.TypeCyclingTurretBehavior
	/**
	 * ...
	 * @author morgan
	 */
	public class Stage9State extends GameState
	{
		
		public function Stage9State() 
		{
			levelName = "3-3";
			levelIndex = 8;
			chefName = "julienne";
			img_terrain = img_terrain_3;			
		}
		
		override public function setupBoss():void 
		{
			boss = new Boss(FlxG.width / 2 - 70, 10, 2);
			clouds2.color = 0x000000;
			clouds2.alpha = 0.5;	
			
			var straight:BulletPattern = new BulletPattern();
			
			var wavey:BulletPattern = new BulletPattern();
			wavey.addBehavior(new WaveBehaviorAngular(1, 360, 0));
		
			var multisplit:BulletPattern = new BulletPattern();
			multisplit.addBehavior(new SplitBehavior(20, 80, 0, 360, straight, Bullet.ROTTEN), 0);
			multisplit.addBehavior(new SplitBehavior(20, 80, 9, 369, straight, 0), 0.2);
			multisplit.addBehavior(new SplitBehavior(20, 80, 0, 360, straight, Bullet.ROTTEN), 0.4);
			multisplit.addBehavior(new SplitBehavior(20, 80, 9, 369, straight, 1), 0.6);
			multisplit.addBehavior(new SplitBehavior(20, 80, 0, 360, straight, Bullet.ROTTEN), 0.8);
			multisplit.addBehavior(new SplitBehavior(20, 80, 9, 369, straight, 2), 1.0);
			multisplit.addBehavior(new DieBehavior(), 1.0);
			
			var multisplitB:BulletPattern = new BulletPattern();
			multisplitB.addBehavior(new SplitBehavior(20, 80, 0, 360, straight, Bullet.ROTTEN), 0);
			multisplitB.addBehavior(new SplitBehavior(20, 80, 9, 369, straight, Bullet.ROTTEN), 0.4);
			multisplitB.addBehavior(new SplitBehavior(20, 80, 0, 360, straight, Bullet.ROTTEN), 0.8);
			multisplitB.addBehavior(new DieBehavior(), 1.0);
			
			var multisplitC:BulletPattern = new BulletPattern();
			multisplitC.addBehavior(new SplitBehavior(12, 40, 0, 360, wavey, Bullet.ROTTEN), 0);
			multisplitC.addBehavior(new SplitBehavior(12, 40, 15, 375, wavey, Bullet.ROTTEN), 0.8);
			multisplitC.addBehavior(new SplitBehavior(12, 40, 0, 360, wavey, Bullet.ROTTEN), 1.6);
			multisplitC.addBehavior(new DieBehavior(), 2.0);					
			
			var split:BulletPattern = new BulletPattern();
			split.addBehavior(new SplitBehavior(16, 60, -90, 90, straight, -1));
			split.addBehavior(new DieBehavior());
			
			var home:BulletPattern = new BulletPattern();
			home.addBehavior(new HomeTargetBehavior(player, Math.PI / 2), 0, 0.8);
			
			var p1f:BossPattern = new BossPattern();
			var t1t:Turret = new Turret(0, 0, multisplit, Bullet.ROTTEN, 0, 1, 1.2);
			var t2t:Turret = new Turret(0, 0, multisplitB, Bullet.ROTTEN, 0, 1, 1.2);
			var t3t:Turret = new Turret(0, 0, straight, Bullet.CANDY, 90, 80, 0.1);
			t3t.addBehavior(new SpinningTurretBehavior(-90));
			p1f.addTurretTime(0, 4, t2t);
			p1f.addTurretTime(1, 4, t3t);
			p1f.addTurretTime(4, 16, t1t);
			
			
			var p2f:BossPattern = new BossPattern();
			var t4t:Turret = new Turret(0, 0, straight, Bullet.ROTTEN, 0, 40, 0.1, true); t4t.addBehavior(new SpinningTurretBehavior(30));
			var t5t:Turret = new Turret(0, 0, straight, Bullet.ROTTEN, 180, 40, 0.1, true); t5t.addBehavior(new SpinningTurretBehavior(30));
			p2f.addTurretTime(0, Infinity, t4t);  p2f.addTurretTime(0, Infinity, t5t);
			for (var i:int = 0; i < 11; i++)
			{
				var n:int = int(i / 2) % 3 
				var ttop:Turret = new Turret((i - 5) * 20, 120, straight, 0, -90, 40, 1.0, true);
				ttop.addBehavior(new TypeCyclingTurretBehavior(1.0, [n, (n+1)%3, (n+2)%3]));
				p2f.addTurretTime(i / 11, Infinity, ttop);
			}
			
			var p3f:BossPattern = new BossPattern();
			var t6t:Turret = new Turret(0, 0, wavey, Bullet.ROTTEN, 0, 40, 0.1, true); t6t.addBehavior(new SpinningTurretBehavior(20));
			var t7t:Turret = new Turret(0, 0, wavey, Bullet.ROTTEN, 180, 40, 0.1, true); t7t.addBehavior(new SpinningTurretBehavior(20));
			//var t8t:Turret = new Turret(0, 0, wavey, Bullet.ROTTEN, 240, 40, 0.1, true); t8t.addBehavior(new SpinningTurretBehavior(20));
			
			p3f.addTurretTime(0, Infinity, t6t);  p3f.addTurretTime(0, Infinity, t7t); //p3f.addTurretTime(0, Infinity, t8t);
			
			var tcandy:Turret = new Turret(0, 0, straight, 0, 45, 40, 0.25, false);
			tcandy.addBehavior(new SpinningTurretBehavior(30, 90, true));
			p3f.addTurretTime(0, Infinity, tcandy);
			
			var t9t:Turret = new Turret(0, 0, multisplitC, Bullet.ROTTEN, 0, 1, 2.4, true);
			p3f.addTurretTime(0, Infinity, t9t);
			
			var p4f:BossPattern = new BossPattern();
			var t10t:Turret = new Turret(0, 0, split, 0, 90, 50, 0.5, false); t10t.addBehavior(new TypeCyclingTurretBehavior(0.5, [0, 1, 2, Bullet.ROTTEN]));
			for (i = 0; i < 10; i++)
			{
				var tt:Turret = new Turret(0, 0, home, Bullet.ROTTEN, 90, 100 + i * 5, 1.0);
				p4f.addTurretTime(i / 20, 2, tt);
			}
			p4f.addTurretTime(0, 2, t10t);
			
			
			boss.addState(new BossState(1000, p1f));
			boss.addState(new BossState(1400, p2f));
			boss.addState(new BossState(600, p3f));
			boss.addState(new BossState(1200, p4f));
		}
	}

}